package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.system.domain.WxMiniMenu;
import com.ruoyi.system.domain.vo.WxMiniRoleVo;
import com.ruoyi.system.service.IWxMiniMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 小程序功能模块Controller
 *
 * @author yy
 * @date 2021-11-03
 */
@Api(tags = " 小程序功能模块")
@RestController
@RequestMapping("/wxMiniMenu")
public class WxMiniMenuController extends BaseController {
    @Autowired
    private IWxMiniMenuService wxMiniMenuService;

    /**
     * 查询小程序功能模块列表
     */
    @ApiOperation(value="查询小程序功能模块列表", notes="查询小程序功能模块列表")
    @PreAuthorize(hasPermi = "system:wxMiniMenu:list")
    @GetMapping("/list")
    public TableDataInfo list(WxMiniMenu wxMiniMenu) {
        startPage();
        List<WxMiniMenu> list = wxMiniMenuService.selectWxMiniMenuList(wxMiniMenu);
        return getDataTable(list);
    }



    /**
     * 查询小程序功能模块列表
     */
    @ApiOperation(value="查询小程序功能模块及对应权限列表", notes="查询小程序功能模块及对应权限列表")
    @PreAuthorize(hasPermi = "system:wxMiniMenu:list")
    @GetMapping("/listVo")
    public AjaxResult meunListWithRole(Long roleId) {
        List<WxMiniRoleVo> list = wxMiniMenuService.selectMenusWithRole(roleId);
        return  AjaxResult.success(list);
    }

    /**
     * 查询小程序功能模块列表
     */
    @ApiOperation(value="查询小程序功能模块及对应权限列表Plus", notes="查询小程序功能模块及对应权限列表Plus")
    @PreAuthorize(hasPermi = "system:wxMiniMenu:list")
    @GetMapping("/listVoPlus")
    public AjaxResult meunListWithRolePlus(@RequestParam List<String> roleIds) {
        //List<WxMiniRoleVo> result = new ArrayList<WxMiniRoleVo>();
        //根据数组查询
        List<WxMiniRoleVo> result = wxMiniMenuService.selectMenusWithRoles(roleIds);
        return  AjaxResult.success(result);
    }

    /**
     * 导出小程序功能模块列表
     */
    @ApiOperation(value="导出小程序功能模块列表", notes="导出小程序功能模块列表")
    @PreAuthorize(hasPermi = "system:wxMiniMenu:export")
    @Log(title = "小程序功能模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxMiniMenu wxMiniMenu) throws IOException {
        List<WxMiniMenu> list = wxMiniMenuService.selectWxMiniMenuList(wxMiniMenu);
        ExcelUtil<WxMiniMenu> util = new ExcelUtil<WxMiniMenu>(WxMiniMenu.class);
        util.exportExcel(response, list, "小程序功能模块数据");
    }
    /**
     * 获取小程序功能模块详细信息
     */
    @ApiOperation(value="获取小程序功能模块详细信息", notes="获取小程序功能模块详细信息")
    @PreAuthorize(hasPermi = "system:wxMiniMenu:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(wxMiniMenuService.selectWxMiniMenuById(id));
    }

    /**
     * 新增小程序功能模块
     */
    @ApiOperation(value="新增小程序功能模块", notes="新增小程序功能模块")
    @PreAuthorize(hasPermi = "system:wxMiniMenu:add")
    @Log(title = "小程序功能模块", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxMiniMenu wxMiniMenu) {
        return toAjax(wxMiniMenuService.insertWxMiniMenu(wxMiniMenu));
    }

    /**
     * 修改小程序功能模块
     */
    @ApiOperation(value="修改小程序功能模块", notes="修改小程序功能模块")
    @PreAuthorize(hasPermi = "system:wxMiniMenu:edit")
    @Log(title = "小程序功能模块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxMiniMenu wxMiniMenu) {
        return toAjax(wxMiniMenuService.updateWxMiniMenu(wxMiniMenu));
    }

    /**
     * 删除小程序功能模块
     */
    @ApiOperation(value="删除小程序功能模块", notes="删除小程序功能模块")
    @ApiImplicitParam(name = "ids", value = "小程序功能模块ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "system:wxMiniMenu:remove")
    @Log(title = "小程序功能模块", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wxMiniMenuService.deleteWxMiniMenuByIds(ids));
    }
}
